package com.ruoyi.web.controller.datastatistics;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.datastatistics.domain.PublicShare;
import com.ruoyi.datastatistics.service.IPublicShareService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公摊配置表Controller
 * 
 * @author zt
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/datastatistics/publicShare")
public class PublicShareController extends BaseController
{
    @Autowired
    private IPublicShareService publicShareService;

    /**
     * 查询公摊配置表列表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicShare publicShare)
    {
        startPage();
        publicShare.setTenantId(getLoginUser().getTenantId());
//        List<PublicShare> list = publicShareService.selectPublicShareList(publicShare);
        List<PublicShare> list = publicShareService.selectPublicShareListInSql(publicShare);
        return getDataTable(list);
    }

    /**
     * 查询公摊配置表列表
     */
    @GetMapping("/getAll")
    public AjaxResult getAll(PublicShare publicShare)
    {
        publicShare.setTenantId(getLoginUser().getTenantId());
//        return AjaxResult.success(publicShareService.selectPublicShareList(publicShare));
        return AjaxResult.success(publicShareService.selectPublicShareListInSql(publicShare));
    }

    /**
     * 导出公摊配置表列表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:export')")
    @Log(title = "公摊配置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PublicShare publicShare)
    {
        List<PublicShare> list = publicShareService.selectPublicShareList(publicShare);
        ExcelUtil<PublicShare> util = new ExcelUtil<PublicShare>(PublicShare.class);
        util.exportExcel(response, list, "公摊配置表数据");
    }

    /**
     * 获取公摊配置表详细信息
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(publicShareService.selectPublicShareById(id));
    }

    /**
     * 新增公摊配置表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:add')")
    @Log(title = "公摊配置表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicShare publicShare)
    {
        publicShare.setTenantId(getLoginUser().getTenantId());
        return toAjax(publicShareService.insertPublicShare(publicShare));
    }

    /**
     * 修改公摊配置表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:edit')")
    @Log(title = "公摊配置表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicShare publicShare)
    {
        return toAjax(publicShareService.updatePublicShare(publicShare));
    }

    /**
     * 删除公摊配置表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:publicShare:remove')")
    @Log(title = "公摊配置表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(publicShareService.deletePublicShareByIds(ids));
    }

    /**
     * 一键过户
     */
    @Log(title = "一键过户", businessType = BusinessType.INSERT)
    @PostMapping("/transferPublicShare")
    public AjaxResult transferPublicShare(@RequestBody PublicShare publicShare)
    {
        publicShare.setTenantId(getLoginUser().getTenantId());
        return toAjax(publicShareService.transferPublicShare(publicShare));
    }
}
